package A_c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo1 {
    public void getSimpleConnect() throws PropertyVetoException, SQLException {
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setDriverClass("com.mysql.cj.jdbc.Driver");//load the jdbc driver
        cpds.setJdbcUrl("jdbc:mysql://localhost/db_rpb");
        cpds.setUser("root");
        cpds.setPassword("123456");
        System.out.println(cpds);
        //com.mchange.v2.c3p0.ComboPooledDataSource[ identityToken -> 1hge9jmaq1ohj01xtdsjdx|4bb4de6a, dataSourceName -> 1hge9jmaq1ohj01xtdsjdx|4bb4de6a ]
        //通过连接池对象获取Connection连接
        Connection conn = cpds.getConnection();
        System.out.println(conn);
        //com.mchange.v2.c3p0.impl.NewProxyConnection@10d68fcd [wrapping: com.mysql.cj.jdbc.ConnectionImpl@117e949d]
        Statement sta = conn.createStatement();

    }
}

